﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient; 
using Microsoft.ApplicationBlocks.Data;

namespace NTTDATA.BEENChina.ResultCertification.DataStore
{
    public class GridItemsAccess:IGridItemsAccess
    {
        private static string ConnectionString
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["ResultCertificationDB"];
            }
        }

        public Dictionary<string, string> GetGridItems(string caId)
        {
            string sql =    " SELECT [ItemValue],[ItemName] " +
                            " FROM  [GridItems]  " +
                            " WHERE [CategoryID] = @CategoryID ";

            SqlParameter[] sqlParameters = 
                {
                    new SqlParameter("@CategoryID",  caId)
                };

            Dictionary<string, string> gridItems = null;
            try
            {
                using (
                    SqlDataReader reader = SqlHelper.ExecuteReader(ConnectionString, System.Data.CommandType.Text, sql,
                                                                   sqlParameters))
                {
                    while (reader.Read())
                    {

                        if (gridItems == null)
                            gridItems = new Dictionary<string, string>();

                        gridItems.Add(reader["ItemValue"].ToString(),reader["ItemName"].ToString());
  
                    }

                    reader.Close();
                }
            }
            catch (Exception ex)
            {
                Log.Console.Error("GridItemsAccess.GetGridItems", ex);
            }

            return gridItems;
        }
    }
}
